<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>出入库明细报表</title>
    <jsp:include page="/WEB-INF/view/commons/css.jsp" />
</head>
<body >
<div id="main-container" class="container-fluid">
    <form action="reportOutAndIn/dolist" method="post" name="searchForm" id="searchForm" role="form" class="form-horizontal">
        <input type="hidden" name="orgId" id="orgId" value="0">
            <div class="form-group">
                    <label class="col-sm-1 control-label">物资名称：</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" id="materialsName" name="materialsName" value="${entity.materialsName}" placeholder="物资名称">
                    </div>
                    <label class="col-sm-1 control-label">单据号：</label>
                    <div class="col-md-4">
                		<input type="text" class="form-control" id="code" name="code" value="${entity.code}" placeholder="单据号">                           
                    </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-1 control-label">来往单位：</label>
                <div class="col-md-2">
                    <d:select clazz="selectpicker" list="${orgTypes}" name="orgType" id="selorgtype" selected="${orgType}"></d:select>
                </div>
                <div class="col-md-2" style="padding-right: 0;display: ${orgType eq '1'?'block':'none'}" id="inOrg">
                    <d:select clazz="selectpicker" list="${orgLists}" name="orgId" id="selinorg" selected="${searchEntity.orgId}"></d:select>
                </div>
                <div class="col-md-2" style="padding-right: 0;display: ${orgType eq '2'?'block':'none'}" id="outOrg">
                    <d:select clazz="selectpicker" list="${outLists}" name="orgId" id="seloutorg" selected="${searchEntity.orgId}"></d:select>
                </div>
                    <label class="col-sm-1 control-label">类型：</label>
                    <div class="col-md-4">
                		<d:select name="storageType" id="storageType" clazz="selectpicker" list="${storageTypes}" selected="${entity.storageType}"/>                                
                    </div>
            </div>
            
           	
			<div class="form-group">
				<label class="col-sm-1 control-label">时间：</label>
				<div class="col-md-6">
					<input type="text" class="span1 Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd', maxDate:'#F{$dp.$D(\'endAddTime\')}'})" id="beginAddTime" name="beginAddTime" value="${searchEntity.beginAddTime}" placeholder="开始时间" /> 至 
					<input type="text" class="span1 Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd', minDate:'#F{$dp.$D(\'beginAddTime\')}'})" id="endAddTime" name="endAddTime" value="${searchEntity.endAddTime}" placeholder="结束时间" />
					<button id="searchBtn" type="button" class="btn btn-sm btn-info"><i class="fa fa-search"></i> 查询</button>
					<a id="export_menu_btn" onclick = exportexcal() class="btn btn-sm btn-pink"><i class="fa fa-file-excel-o icon-share"></i> 导出</a>
				</div>
			</div>	
    </form>
    
    <form id= "exportexcalform" method=post action="${ctx}reportOutAndIn/export" target="_blank" >
					<input type="hidden" name="materialsName"  />
					<input type="hidden" name="code"  />
					<input type="hidden" name="orgName"  />
					<input type="hidden" name="storageType"  />
					<input type="hidden" name="beginAddTime"  />
					<input type="hidden" name="endAddTime"  />
	</form>
    
    <table id="table_data" class="table table-striped table-bordered table-hover">
        <thead>
        <tr>
            <th width="10%">单据号</th>
            <th width="10%">物资编号</th>
            <th width="10%">物资名称</th>
            <th width="9%">出入库类型</th>
            <th width="8%">规格</th>
            <th width="8%">单位</th>
            <th width="8%">数量</th>
            <th width="12%">来往单位</th>
            <th width="10%">经办人</th>
            <th width="15%">出入库时间</th>
           	<th width="6%">操作</th>
        </tr>
         
        </thead>
        <tbody>
        </tbody>
    </table>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
    <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
</a>
<!-- script start -->
<jsp:include page="/WEB-INF/view/commons/js.jsp" />
<script type="text/javascript">
    $(document).ready(function(e) {
        var table = $("#table_data").dataTable({
            ajax: function(data, callback, settings){
                tableAjax($("#searchForm"),data, callback, settings);
            },
            columnDefs: [{
                targets: 2,
                createdCell: function (td, cellData, rowData, row, col) {
                    if ( rowData.status == '3' ) {
                        $(td).parent().css('color', 'red');
                    }
                }
            }],
            //列表表头字段
            columns: [
                { "data": "code",name:"code",orderable:false },
                { "data": "materialsCode",name:"materials_code",orderable:false },
                { "data": "materialsName",name:"materials_name",orderable:false },
                { "data": "storageTypeStr",name:"storage_type", orderable:false },
                { "data": "specification",name:"specification",orderable:false },
                { "data": "unit",name:"unit",orderable:false },
                { "data": "num",name:"num",orderable:false },
                { "data": "orgName",name:"org_name",orderable:false },
                { "data": "agentName",name:"agent_name",orderable:false },
                { "data": "timeStr",name:"time",orderable:false },
                {
                    "data": "action",orderable:false,
                    "render": function ( data, type, row, meta ) {
                    	console
                    	var infoOut = "<a href='javacript:void(0);' onclick=\"show_out('" + row.id + "');\">查看</a>";
                    	var infoIn = "<a href='javacript:void(0);' onclick=\"show_in('" + row.id + "');\">查看</a>";
                       if(row.storageType == 1){
                    	   return infoOut;
                       }
                       if(row.storageType == 2){
                    	   return infoIn;
                       } 
                       return "";
                    }
                	
                }
        ]
    }).api();

        //查询条件
        $("#searchForm").submit(function(){
            table.ajax.reload();
            return false;
        });

        $("#selorgtype").change(function (){
            var orgtype = $(this).val();
            if(orgtype == '1'){
                $("#inOrg").css("display","block");
                $("#outOrg").css("display","none");
                $("#orgId").val($("#selinorg").val());
            }else{
                $("#inOrg").css("display","none");
                $("#outOrg").css("display","block");
                $("#orgId").val($("#seloutorg").val());
            }
        });

        $("#selinorg").change(function(){
            var orgid = $(this).val();
            $("#orgId").val(orgid);
        });

        $("#seloutorg").change(function(){
            var orgid = $(this).val();
            $("#orgId").val(orgid);
        });
    });
    
  //点击导出 将页面数据加载到表单中
	function exportexcal(){
		if($.trim($("#materialsName").val())=='' && $.trim($("#code").val())=='' &&
            $.trim($("#seloutorg").val())=='' && $.trim($("#storageType").val())=='' && $.trim($("#selinorg").val())=='' &&
            $.trim($("#beginAddTime").val())=='' && $.trim($("#endAddTime").val())=='' ){
			layer.msg("没有任何筛选条件，系统无法筛选结果，导出动作被取消！");
			return false;
		} 
		$('#exportexcalform input[name="materialsName"]').val($.trim($("#materialsName").val()));
		$('#exportexcalform input[name="code"]').val($.trim($("#code").val()));
        var orgid ;
		if($("#selorgtype").val() == '1'){
            orgid = $.trim($("#selinorg").val());
        }else{
            orgid = $.trim($("#seloutorg").val());
        }
		$('#exportexcalform input[name="orgName"]').val(orgid);
		$('#exportexcalform input[name="storageType"]').val($.trim($("#storageType").val()));
		$('#exportexcalform input[name="beginAddTime"]').val($.trim($("#beginAddTime").val()));
		$('#exportexcalform input[name="endAddTime"]').val($.trim($("#endAddTime").val()));
		$('#exportexcalform').submit();
	}
    
	   //查看出库单签署过后的文件
	    function show_out(id){
	        var option={
	            url:"appMaterialsOut/outPrintSigned/"+id,
	            title:"查看出库单",
	            width:"60%",
	            height:"90%"
	        };
	        openIframe(option);
	    }
	   
	  //查看入库单签署过后的文件
	    function show_in(id){
	        var option={
	            url:"appMaterialsIn/inSignPrint/"+id,
	            title:"查看入库单",
	            width:"60%",
	            height:"90%"
	        };
	        openIframe(option);
	    }
    
</script>
<!-- script end -->
</body>
</html>